import {setItem} from '../utils/utils';
export default {
    UP_USR({ commit }, data) {
        return new Promise(async (resolve, reject) => {
            await setItem('usr', data)
            commit('SET_USER', data);
            resolve(true)
        });
    },
    
    GET_STATE({state,commit}) {
        return new Promise((resolve, reject) => {
            let usr = localStorage.getItem('usr')
            if (state.isLogin) {
                resolve(true)
            } else if (usr) {
                if (typeof usr === "string") {
                    usr = JSON.parse(usr)
                }
                commit('LOGIN',usr)
                resolve(true)
            } else {
                reject(false)
            }
        });
    },
}